package com.example.springboot.exception;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.example.springboot.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;



/**
 * 功能:
 * 作者: whs
 * 日期:20240921 14:15:00
 */
@ControllerAdvice("com.example.springboot.controller")
public class GlobalExceptionHandler {

    private static final Log log=LogFactory.get();

    @ExceptionHandler(Exception.class)
    @ResponseBody //返回JSON
    public Result error(Exception e){
        log.error("异常信息",e);
        return Result.error();
    }

    @ExceptionHandler(CustomException.class)
    @ResponseBody //返回JSON
    public Result error(CustomException e){
//        log.error("异常信息",e);
        return Result.error(e.getCode(),e.getMsg());
    }
}